1. Field of the Invention
The invention relates to a mobile electronic device, and particularly relates to a method for clearing memory blocks of the mobile electronic device.
2. Description of Related Art
FIG. 1 is a schematic diagram illustrating a conventional flash memory 100. The flash memory 100 includes two memory blocks 110 and 120, and each of the memory blocks includes 16 memory pages. Initially, a file takes up five memory pages A1 to E1 of the memory block 110, as shown in FIG. 1.
A characteristic of the flash memory is that units for data programming and data erasing are not symmetrical. Specifically, the unit for data programming is the memory page, which is smaller, and the unit for data erasing is the memory block, which is larger. Thus, when the content of the file is modified, the original memory pages A1 to E1 are not overwritten. Instead, the modified file is written to subsequent memory pages A2 to E2, as shown in FIG. 2. If the content of the file is then further modified, the file that is newly modified will be written to subsequent pages A3 to E3, and so on so forth. Older data in the memory pages A1 to E1 and A2 to E2 are also termed as invalid data.
The conventional mobile electronic device uses flash memory as the main storage device, e.g. solid state disks (SSD) or embedded multimedia cards (eMMC), for storing an operating system, applications, and a variety of data. However, fragmentation, as shown in FIG. 2, may be found after the flash memory is used for a period of time. In other words, the memory blocks may store a certain amount of invalid data. If the invalid data are not cleared, the free memory blocks will become less and less as the invalid data accumulate.
To recycle the memory pages A1 to E1 and A2 to E2 taken up by the invalid data, the valid data in the memory pages A3 to E3 may be copied to another memory block 120, and then the memory block 110 is erased, as shown in FIG. 3. This kind of recycling process is termed as garbage collection. Garbage collection usually takes a long time, which may make the mobile electronic device operate with delay or cease to function and may thus influence user experience.